/**
 * 引入浏览器自带分享功能的插件
 */
import Vue from 'vue'

const onPlusReady = function (callback, context = this) {
   if (window.plus) {
      callback.call(context)
   } else {
      document.addEventListener('plusready', callback.bind(context))
   }
}
Vue.mixin({
   beforeCreate() {
      onPlusReady(() => { this.plusReady = true }, this)
   },
   methods: {
      onPlusReady: onPlusReady
   }
})


// 将App分享给QQ好友
function shareQQ() {
   try {
      // nativeShare.call('qqFriend')
      plus.share.getServices((successCB) => {
         console.log(successCB)
      }, (errorCB) => { console.log(errorCB) })
   } catch (err) {
      // shareDefault()
      alert('该浏览器不支持')
   }
}

// 将App分享到微博
function shareWeibo() {
   try {
      nativeShare.call('weibo')
   } catch (err) {
      // shareDefault()
      alert('该浏览器不支持')
   }
}

export {
   shareWechat,
   shareQQ,
   shareWeibo
}